package com.atstudent.gmall.web.controller;

import com.atstudent.gmall.common.feign.item.SkuDetailFeignClient;
import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.product.vo.SkuDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @Author 薛有朋
 * @CreatDate 2024/12/1 18:01
 **/
@Controller
public class ItemController {

    @Autowired
    private SkuDetailFeignClient skuDetailFeignClient;

    @GetMapping(value = "{skuId}.html")
    public String item(@PathVariable(value = "skuId") Long skuId , Model model){
        //调用feign得到数据
        Result<SkuDetailVo> skuDetailVoResult = skuDetailFeignClient.item(skuId);
        SkuDetailVo skuDetailVo = skuDetailVoResult.getData();

        //数据塞入到model模型中
        model.addAttribute("categoryView" , skuDetailVo.getCategoryView());
        model.addAttribute("skuInfo" , skuDetailVo.getSkuInfo()) ;
        model.addAttribute("price" , skuDetailVo.getPrice()) ;
        model.addAttribute("spuSaleAttrList" , skuDetailVo.getSpuSaleAttrList()) ;
        model.addAttribute("valuesSkuJson" , skuDetailVo.getValuesSkuJson()) ;

        //返回页面
        return "item/index";
    }
}
